package com.redlight.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by chao on 2019/1/9.
 */
public abstract class RestBaseController extends BaseController {
    public RestBaseController() {
    }

    protected String getUserId(HttpServletRequest request) {
        return (String)request.getSession().getAttribute("SubjectId");
    }

    protected SysUser getUser(HttpServletRequest request) {
        HttpSession session = request.getSession();
        SysUser user = (SysUser)session.getAttribute("user");
        if(null == user) {
            String subjectId = this.getUserId(request);
            if(null != subjectId && 0 < subjectId.length()) {
                user = UserUtils.getUserById(subjectId);
                session.setAttribute("user", user);
                return user;
            }
        }

        return user;
    }

    protected String getAuthorization(HttpServletRequest request) {
        String Authorization = (String)request.getSession().getAttribute("Authorization");
        return Authorization;
    }
}
